Skip to content

fix(sdk): retry captcha-request on 422 'Session not active' race#5

Open
iWedmak wants to merge 1 commit into
masterfrom
fix/sdk-captcha-retry-race
Open

fix(sdk): retry captcha-request on 422 'Session not active' race#5
iWedmak wants to merge 1 commit into
masterfrom
fix/sdk-captcha-retry-race

Conversation

@iWedmak

@iWedmak iWedmak commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

browser.request_captcha() calls POST /api/agent/sessions/{id}/captcha-request right after rent(). The back marks the session active immediately, but the provider-WS attach on the relay lands a few hundred ms later — in that window the back returns 422 'Session not active'.

Retry up to 5 times with backoff 0 / 0.5 / 1 / 2 / 4s when the 422 body matches Session not active. Other 422 bodies (validation, 'not configured') stay terminal.

Why

Without this, a tight rent() → request_captcha() chain fails ~100% of the time on dev. SDK callers shouldn't have to sleep before the first action.

Test plan

  • CLI: ceki rent --schedule N && ceki request-captcha <SID> succeeds without manual sleep
  • Existing tests/test_captcha.py still green

After rent() the back marks the session 'active' immediately, but the
provider WS attach on the relay lands a few hundred ms later. Calling
request-captcha in that window returns 422 'Session not active' from
AgentCaptchaRequestController.

Retry up to 5 times with backoff 0.5/1/2/4s when the 422 body matches
'Session not active'. Other 422 bodies (validation, 'not configured')
are still treated as terminal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant